package com.uu.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    @Transactional(transactionManager = "transactionManager1")
    public void user() {
        System.out.println("getCurrentTransactionName--" + TransactionSynchronizationManager.getCurrentTransactionName());
        jdbcTemplate.execute("INSERT INTO account ( name, balance) VALUES ( 'sg2', 22)");
        this.user2();
    }

    @Override
    @Transactional(transactionManager = "transactionManager1")
    public void user2() {
        System.out.println("getCurrentTransactionName2--" + TransactionSynchronizationManager.getCurrentTransactionName());
        jdbcTemplate.execute("INSERT INTO account ( name, balance) VALUES ( 'sg3', 33)");
    }
}
